package com.rttmall.shopbackend.app.gambling.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
import com.rttmall.shopbackend.app.gambling.pojo.GamblingPeriodCustom;
import com.rttmall.shopbackend.app.gambling.service.GamblingPeriodService;
import com.rttmall.shopbackend.enums.PeriodStatus;
import com.rttmall.shopbackend.pojo.Pagination;

@Controller
@RequestMapping("gamblingPeriod")
public class GamblingPeriodController {
	

	@Autowired
	private GamblingPeriodService gamblingPeriodService;

	@RequestMapping(method = RequestMethod.GET)
	public String findGamblingPeriod() {
		return "app/gambling/GamblingPeriodList";
	}
	@RequestMapping("findPeriod")
	public String findPeriod() {
		return "app/gambling/PeriodList";
	}
	@RequestMapping(value = "/queryGamblingPeriod")
	public @ResponseBody Map queryGamblingPeriod(
			@RequestParam(defaultValue = "") String json, Pagination grid) {
		GamblingPeriodCustom gamblingPeriodCustom = JSON.parseObject(json,
				GamblingPeriodCustom.class);
		if (null == gamblingPeriodCustom) {
			gamblingPeriodCustom = new GamblingPeriodCustom();
		}
		if(null != gamblingPeriodCustom.getStartDate()){
			gamblingPeriodCustom.setStartTime(gamblingPeriodCustom.getStartDate().getTime());
		}
		if(null != gamblingPeriodCustom.getEndDate()){
			gamblingPeriodCustom.setEndTime(gamblingPeriodCustom.getEndDate().getTime());
		}
		grid.setStartIndex(grid.getPageIndex() * grid.getPageSize());
		gamblingPeriodCustom.setPagination(grid);
		Map map = gamblingPeriodService.queryGamblingPeriod(gamblingPeriodCustom);
		return map;
	}

	@RequestMapping("/getPeriodStatus")
	public @ResponseBody List getPeriodStatus() {
		List list = new ArrayList<>();
		for (PeriodStatus e : PeriodStatus.values()) {
			list.add(e);
		}
		return list;
	}
}
